package Stack;

public class MyQueue {
    static class Lisnode{
        public int val;
        public Lisnode prev;
        public Lisnode next;

        public Lisnode(int val){
            this.val=val;
        }
    }
    public Lisnode first=null;
    public Lisnode last=null;
    public int usedSize=0;

    public void offer(int val){
        Lisnode node=new Lisnode(val);
        if(isEmpty()){
            first=last=node;
        }else {
            last.next=node;
            node.prev=last;
            last=last.next;
        }
        usedSize++;
    }

    public int poll(){
        if(isEmpty()){
            return -1;
        }
        int val= first.val;
       first=first.next;
       if(first!=null){
           first.prev=null;
       }
       return val;
    }
    public int peek(){
        if(isEmpty()){
            return -1;
        }
        return first.val;
    }

    public boolean isEmpty(){
        return usedSize==0;
    }
}
